﻿using System;
using System.Collections.Generic;
using System.Linq;
using studentSubsidy.Entity.Home;
using studentSubsidy.Models;
using studentSubsidy.Utils;

namespace studentSubsidy.Dao
{
    public class HomeDao
    {
        private SqlCommandExecutor _sqlCommandExecutor = new SqlCommandExecutor();
        private MyDbContext DBContext = new MyDbContext();

        public List<Picture> getCarousel()
        {
            List<Picture> carouselList = DBContext.Picture.Where(q => q.type == "carousel").ToList();
            return carouselList;
        }

        public List<Project> getProjectByCategory(int category_id_query)
        {
            List<Project> projectList = new List<Project>();
            if (category_id_query == 1)
            {
                projectList = DBContext.Project.Where(p => p.category_id <= 2).ToList()
                    .GetRange(0, 7);
            }
            else
            {
                projectList = DBContext.Project.Where(p => p.category_id <= 4 && p.category_id > 2).ToList()
                    .GetRange(0, 7);
            }

            return projectList;
        }

        public List<Project> getAllProject()
        {
            List<Project> projectList = DBContext.Project.ToList();
            return projectList;
        }

        public List<Project> getProjectByCategoryPage(ProjectQuery projectQuery)
        {
            if (projectQuery.category_id[0] == 1)
            {
                return  DBContext.Project.Where(p => p.category_id == 1 || p.category_id ==2)
                    .ToList();
            }
            if (projectQuery.category_id[0] == 2)
            {
                return DBContext.Project.Where(p => p.category_id == 3|| p.category_id ==4)
                    .ToList();
            }

            return null;
        }
    }
}